<template>
	<view class="page" :style="themeColor">
		<view class="flex flex-direction flex-wrap align-stretch benben-position-layout flex shoppingCart_flex_0"
			:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class='flex flex-wrap align-center justify-between shoppingCart_fd0_0'>
				<view class='flex flex-wrap align-center shoppingCart_fd0_0_c0'>
				</view>
				<view class='flex flex-wrap align-center'>
					<text class='shoppingCart_fd0_0_c1_c0'>购物车</text>
				</view>
				<view class='flex align-center justify-end shoppingCart_fd0_0_c2' @tap.stop="changeEditor">
					<text class='shoppingCart_fd0_0_c2_c0' v-if="isEditor===false">管理</text><text
						class='shoppingCart_fd0_0_c2_c0_1' v-if="isEditor===true">完成</text>
				</view>
			</view>

		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
		<view class="loading_css" v-if="!isShow">
			<u-loading size="36" color="#4177DD"></u-loading>
			<view class="loading_text">加载中</view>
		</view>
		
		<view style="padding-bottom: 120rpx;" v-else>
			<benben-shop-cart :is-editor.sync='isEditor' :cart-list.sync='dataList' :cart-ids.sync='dataId' :cart-index.sync="cartIndex"
				:cart-id.sync='clickId' :goods-id.sync='clickShopId' :sku-id.sync='clickShopSpecifications'
				:cart-num.sync='num' @toGoods="goShopDetailFunc()" @navToLogin="goLogonFunc()" @navToHome="goIndexFunc()"
				@transCartGoods="removeCollectionFunc()" @delCart="deteleFunc()" @createOrder="ConfirmOrderFunc"
				@numberChange="buyNumFunc()" @changeSku="getShopDetailFunc">
			</benben-shop-cart>
			<u-loadmore v-if="last_page > 1" style="padding: 24rpx 0;width: 100%;" :status="status"
				:icon-type="iconType" :load-text="loadText" />
			
			
		</view>
		
		
		<!---规格flex布局结束-->
		<benben-popup v-model="popupShow1653961165769" :mask="true" mode='bottom'>
			<!---规格弹窗flex布局开始-->
			<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout commoDity_flex_6">
				<view class='flex flex-direction flex-wrap align-stretch commoDity_fd6_0'>
					<view class='flex flex-wrap align-center commoDity_fd6_0_c0'>
						<image class='commoDity_fd6_0_c0_c0' mode="aspectFill" :src='classification.sku_img' @tap.stop="previewImg(classification.sku_img)"></image>
						<view class='flex flex-wrap align-center flex-sub'>
							<view class='flex flex-direction flex-wrap align-stretch flex-sub'>
								<view class='flex flex-wrap align-center' style="margin-bottom: 16rpx;">
									<text class='commoDity_fd6_0_c0_c1_c0_c0_c0_1'>￥</text>
									<text class='commoDity_fd6_0_c0_c1_c0_c0_c0'>{{classification.shop_price}}</text>
								</view>
								<view style="display: flex;justify-content: space-between;color: #999;">
									<view class='flex flex-wrap align-center commoDity_fd6_0_c0_c1_c0_c1'>
										<text class='commoDity_fd6_0_c0_c1_c0_c1_c0'>库存：</text>
										<text class='commoDity_fd6_0_c0_c1_c0_c1_c1'>{{classification.stock}}</text>
									</view>
									<view class='flex flex-wrap align-center'>
										<!-- <text class='commoDity_fd6_0_c0_c1_c0_c2_c0'>已选：</text>
										<text class='commoDity_fd6_0_c0_c1_c0_c2_c1'>{{classification.spec_item_name}}</text> -->
									</view>
								</view>
							</view>
							<image class='self-start commoDity_fd6_0_c0_c1_c1' :src='STATIC_URL+"26.png"'
								@tap.stop="popupShow1653961165769=false"></image>
						</view>
					</view>
					
					<view class="sku_lists">
						<scroll-view :scroll-y="true">
							<view class="lists_item " :class="v.sku_id == classification.sku_id ? 'active_item' : ''" v-for="(v, k) in sku_list" :key="k" @tap="selectSpec(k)">
								<image class="lists_item_img" :src="v.sku_img" mode="aspectFill"></image>
								<view class="lists_item_title">{{v.spec_item_name}}</view>
								<view class="lists_item_price">￥{{v.shop_price}}</view>
							</view>
						</scroll-view>
					</view>
					
					<!-- <view class='flex flex-direction flex-wrap align-stretch commoDity_fd6_0_c1' v-for="(v, k) in spec_list" :key="k">
						<text class='commoDity_fd6_0_c1_c0'>{{v.name}}</text>
						<view>
							<view class='flex align-center justify-center flex commoDity_fd6_0_c1_c1_c1' :class="item.isSelect ? 'is_select' : ''" v-for='(item,key) in v.child' :key="key">
								<text class="commoDity_fd6_0_c1_c1_c1_c0" @tap="selectSpec(k, key)">{{item.item}}</text>
							</view>
						</view>
					</view> -->
					<!-- <view class='flex flex-wrap align-center commoDity_fd6_0_c3'>
						<text class='commoDity_fd6_0_c3_c0'>购买数量</text>
		
						<benben-flex-number-box class-name='flex flex align-center'
							input-class="commoDity_numberBoxInputfd6_0_c3_c1" :min="1" :max="classification.stock" :step="1" :opacity="0.5" @input="shopNumber">
							<template #minus>
								<image class='commoDity_fd6_0_c3_c1_c0' mode="aspectFit" :src='STATIC_URL+"150.png"'>
								</image>
							</template>
							<template #plus>
								<image class='commoDity_fd6_0_c3_c1_c2' mode="aspectFit" :src='STATIC_URL+"151.png"'>
								</image>
							</template>
		
						</benben-flex-number-box>
		
					</view> -->
					<!-- <block v-if="!is_hide">
						<button class='commoDity_fd7_0 commoDity_fd7_0_1'
							v-if="Number(userInfo.user_money) < Number(classification.shop_price)">学币不足</button>
						<button v-else  class='commoDity_fd6_0_c4' @tap="getExchange">立即兑换</button>
					</block> -->
					
					<button class='commoDity_fd6_0_c4' @tap.stop="getExchange()">确认选择</button>
				</view>
			</view>
			<!---规格弹窗flex布局结束-->
		</benben-popup>
		
		
		
		<!-- <benben-specs-popup ref="specsPopup1667618639510" :speclist='dataDetails.spec_list'
			:skulist='dataDetails.sku_list' :sku-id.sync='clickShopSpecifications' :sku-name.sync='sku_name'
			:price.sync='dataDetails.shop_price' :thumb.sync='dataDetails.thumb'
			:market-price.sync='dataDetails.market_price' :stock.sync='dataDetails.stock' :number.sync='num'
			@confirm="confirmSelectionFunc()">
		</benben-specs-popup> -->


	</view>
</template>
<script>
	import {
		validate
	} from '@/common/utils/validate.js'
	export default {
		components: {},

		data() {
			return {
				"popupShow1653961165769": false,
				"minixPagingListsApi": "",
				"pageingListApiMethod": "",
				"allowOnloadGetList": false,
				"dataList": [],
				"dataId": "",
				"num": "",
				"cartIndex": "",
				"shopList": [],
				"clickId": "",
				"clickShopId": "",
				"selectBuyId": "",
				"clickShopSpecifications": "",
				"sku_name": "",
				"spec_list": [],
				"sku_list": [],
				"classification": {
					"spec_item_name": '请选择规格',
					"shop_price": '',
				},  // 选择的分类数据
				"spec_item_name": '',
				"isEditor": false,
				
				"page": 1,
				"is_pull": true,
				"last_page": 1,
				"status": 'loadmore',
				"iconType": 'flower',
				"loadText": {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '我也是有底线的'
				},
				"isShow": false
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},
			isLogin() {
				return this.$store.state.token == '' ? false : true;
			}
		},
		watch: {},
		onLoad(options) {

		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			if (this.isLogin) {
				this.page = 1;
				this.is_pull = true;
				this.isShow = false;
				this.DataListFunc()
			} else {
				this.isShow = true;
			}
		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {
			this.page = 1;
			this.is_pull = true;
			this.isShow = false;
			this.DataListFunc()
		},
		onReachBottom(e) {
			if (this.page >= this.last_page) return;
			this.status = 'loading';
			this.page++;
			setTimeout(() => {
					
				if (this.page >= this.last_page) this.status = 'nomore';
				else this.status = 'loading';
				this.is_pull = false;
				this.DataListFunc();
			}, 500)
		},
		onPageScroll(e) {

		},
		methods: {
			//获取购物车列表
			DataListFunc() {
				if (this.isLogin === true) {
					//请求方法
					//数据验证
					this.$api.post(global.apiUrls.post6437b2e45c56b, {
						page: this.page
					}).then(res => {
						// console.log(res);
						uni.stopPullDownRefresh();
						this.isShow = true;
						if (res.data.code == 1) {
							this.last_page = res.data.data.last_page;
							if (this.is_pull) {
								this.dataList = res.data.data.data;
							} else {
								this.dataList = this.dataList.concat(res.data.data.data);
							}
						} else {
							this.$message.info(res.data.msg);
						}
					})
					
				}
				if (this.isLogin === false) {
					return
				}
			},
			changeEditor() {
				this.isEditor = !this.isEditor;
			},
			// 预览图片
			previewImg(url) {
				let arr = [];
				arr.push(url)
				uni.previewImage({
					current: 0,
					urls: arr
				});
			},
			//删除购物车
			deteleFunc() {
				this.$api.post(global.apiUrls.post6437b377d2ded, {
					cart_ids: this.dataId
				}).then(res => {
					this.$message.info(res.data.msg);
					if (res.data.code == 1) {
						this.DataListFunc()
					}
				})
			},
			//移入收藏
			removeCollectionFunc() {
				this.$api.post(global.apiUrls.post6437b38ddf8d0, {
					cart_ids: this.dataId
				}).then(res => {
					this.$message.info(res.data.msg);
					if (res.data.code == 1) {
						this.DataListFunc()
					}
				})
			},
			//购物车商品数量操作
			buyNumFunc() {
				this.$api.post(global.apiUrls.post6437b362d0622, {
					cart_id: this.clickId,
					goods_id: this.clickShopId,
					num: this.num
				}).then(res => {
					this.$message.info(res.data.msg);
					if (res.data.code == 1) {
						this.$set(this.dataList[this.cartIndex], "num", this.num);
					}
				})
			},
			//跳转商品详情
			goShopDetailFunc() {
				this.$urouter.navigateTo(`/pages/homepage/shopDetail/shopDetail?id=${this.clickShopId}`);
			},
			//跳转登录
			goLogonFunc() {
				this.toLoginDiy();
			},
			//跳转首页
			goIndexFunc() {
				this.toHomeDiy();
			},
			//获取商品详情规格
			getShopDetailFunc(e) {
				this.spec_list = e.spec_list
				this.sku_list = e.sku_list
				this.spec_item_name = e.spec_item_name;
				if (this.spec_list.length > 0) {
					let specs = '';
					this.spec_list.forEach((v, k) => {
						if (v.child.length > 0) {
							v.child.forEach((v1, k1) => {
								if (v1.isSelect) {
									specs += v.child[k1].id + '_';
								}
							})
						}
					})
					specs = specs.substring(0, specs.length - 1);
					for(var i in  this.sku_list) {
						if (specs == this.sku_list[i].spec_item_id) {
							this.classification = this.sku_list[i];
						}
					}
					this.popupShow1653961165769 = true;
				} else {
					this.$message.info('暂无规格可以选择');
				}
			},
			ConfirmOrderFunc(e) {
				uni.setStorageSync('goods_info', e);
				uni.navigateTo({
					url: '/pages/Cart/shoppingCartSettlement/shoppingCartSettlement?address_id=' + '' + '&order_type=1'
				})
			},

			// 选择规格
			selectSpec(k, key) {
				this.classification = this.sku_list[k];
				return;
				
				
				
				this.spec_list[k].child.forEach((v, k) => {
					v.isSelect = false;
				})
				this.spec_list[k].child[key].isSelect = true;
				this.$forceUpdate();
				let specs = '';
				this.spec_list.forEach((v, k) => {
					if (v.child.length > 0) {
						v.child.forEach((v1, k1) => {
							if (v1.isSelect) {
								specs += v.child[k1].id + '_';
							}
						})
					}
				})
				specs = specs.substring(0, specs.length - 1);
				for(var i in  this.sku_list) {
					if (specs == this.sku_list[i].spec_item_id) {
						this.classification = this.sku_list[i];
						console.log(this.classification);
					}
				}
			},
			
			// 确认修改sku
			getExchange() {
				this.popupShow1653961165769 = false;
				this.$api.post(global.apiUrls.post6437b348e0d3e, {
					cart_id: this.clickId,
					goods_id: this.clickShopId,
					sku_id: this.classification.sku_id
				}).then(res => {
					this.$message.info(res.data.msg);
					if (res.data.code == 1) {
						this.DataListFunc();
						// this.$set(this.dataList[this.cartIndex], "spec_item_name", this.classification.spec_item_name);
						// this.$set(this.dataList[this.cartIndex], "sku_id", this.classification.sku_id);
						// this.$set(this.dataList[this.cartIndex], "spec_item_id", this.classification.spec_item_id);
						// this.$set(this.dataList[this.cartIndex], "shop_price", this.classification.shop_price);
					}
				})
			},
		}
	};
</script>
<style lang="scss" scoped>
	.sku_lists {
		width: 100%;
		height: 500rpx;
		padding: 0rpx 32rpx;
		scroll-view {
			width: 100%;
			height: 500rpx;
			padding: 24rpx 0;
		}
		.active_item {
			border: 1px solid #009AFF;
			background: #FFFFFF !important;
		}
		.lists_item {
			display: flex;
			align-items: center;
			padding: 16rpx 24rpx;
			border-radius: 16rpx;
			margin-bottom: 12rpx;
			background: #f8f8f8;
			.lists_item_img {
				width: 40rpx;
				height: 40rpx;
				border-radius: 8rpx;
			}
			.lists_item_title {
				font-size: 30rpx;
				flex: 1;
				margin: 0 24rpx;
			}
			.lists_item_price {
				font-size: 28rpx;
				color: #999999;
			}
		}
	}
	.commoDity_fd6_0 {
		background: #fff;
		background-size: 100% !important;
		background-size: 100% auto !important;
		border-radius: 24rpx 24rpx 0rpx 0rpx;
		max-height: 1000rpx;
	}
	
	.commoDity_fd6_0_c0 {
		margin: 30rpx 32rpx 0rpx 32rpx;
	}
	
	.commoDity_fd6_0_c0_c0 {
		width: 200rpx;
		height: 200rpx;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		margin: -60rpx 24rpx 0rpx 0rpx;
	}
	
	.commoDity_fd6_0_c0_c1_c0_c0_c0 {
		font-size: 36rpx;
		font-weight: 700;
		color: rgba(250, 32, 51, 1);
		margin: 0rpx 8rpx 0rpx 0rpx;
		word-wrap: break-word;
	}
	.commoDity_fd6_0_c0_c1_c0_c0_c0_1 {
		font-size: 20rpx;
		font-weight: 700;
		color: rgba(250, 32, 51, 1);
		margin: 0rpx;
		word-wrap: break-word;
	}
	
	.commoDity_fd6_0_c0_c1_c0_c0_c1 {
		font-weight: 400;
		color: rgba(51, 51, 51, 1);
		font-size: 22rpx;
		line-height: 28rpx;
		word-wrap: break-word;
	}
	
	.commoDity_fd6_0_c0_c1_c0_c1 {
		margin: 0rpx 0rpx 8rpx 0rpx;
		transform: translateY(4rpx);
	}
	
	.commoDity_fd6_0_c0_c1_c0_c1_c0 {
		word-wrap: break-word;
	}
	
	.commoDity_fd6_0_c0_c1_c0_c1_c1 {
		word-wrap: break-word;
	}
	
	.commoDity_fd6_0_c0_c1_c0_c2_c0 {
		word-wrap: break-word;
		font-size: 24rpx;
	}
	
	.commoDity_fd6_0_c0_c1_c0_c2_c1 {
		word-wrap: break-word;
		font-size: 24rpx;
	}
	
	.commoDity_fd6_0_c0_c1_c0_c2_c2 {
		word-wrap: break-word;
		font-size: 24rpx;
	}
	
	.commoDity_fd6_0_c0_c1_c1 {
		width: 28rpx;
		height: 28rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}
	
	.commoDity_fd6_0_c1 {
		margin: 32rpx 32rpx 0rpx 32rpx;
	}
	
	.commoDity_fd6_0_c1_c0 {
		font-size: 32rpx;
		font-weight: 500;
		color: rgba(51, 51, 51, 1);
		margin: 0rpx 0rpx 24rpx 0rpx;
		word-wrap: break-word;
	}
	
	.commoDity_fd6_0_c1_c1_c0 {
		border: 1px solid #009AFF;
		background: #FFFFFF;
		background-size: 100% !important;
		width: 144rpx;
		height: 64rpx;
		border-radius: 32rpx 32rpx 32rpx 32rpx;
		margin: 0rpx 24rpx 24rpx 0rpx;
	}
	
	.commoDity_fd6_0_c1_c1_c0_c0 {
		font-size: 28rpx;
		font-weight: 500;
		color: rgba(0, 154, 255, 1);
		word-wrap: break-word;
	}
	
	.commoDity_fd6_0_c1_c1_c1 {
		border: 1px solid #F2F2F2;
		background: #F2F2F2;
		background-size: 100% !important;
		width: 144rpx;
		height: 64rpx;
		border-radius: 32rpx 32rpx 32rpx 32rpx;
		margin: 0rpx 24rpx 24rpx 0rpx;
		float: left;
	}
	.is_select {
		border: 1px solid #3083FF;
		background: rgba(48,131,255,0.05);
		background-size: 100% !important;
		width: 144rpx;
		height: 64rpx;
		border-radius: 32rpx 32rpx 32rpx 32rpx;
		margin: 0rpx 24rpx 24rpx 0rpx;
		float: left;
		color: #3083FF !important;
	}
	
	.commoDity_fd6_0_c1_c1_c1_c0 {
		font-size: 28rpx;
		font-weight: 400;
		// color: rgba(51, 51, 51, 1);
		word-wrap: break-word;
	}
	
	.commoDity_fd6_0_c2 {
		margin: 24rpx 32rpx 0rpx 32rpx;
	}
	
	.commoDity_fd6_0_c2_c0 {
		font-size: 32rpx;
		font-weight: 500;
		color: rgba(51, 51, 51, 1);
		margin: 0rpx 0rpx 24rpx 0rpx;
		word-wrap: break-word;
	}
	
	.commoDity_fd6_0_c2_c1_c0 {
		border: 1px solid #009AFF;
		background: #FFFFFF;
		background-size: 100% !important;
		width: 144rpx;
		height: 64rpx;
		border-radius: 32rpx 32rpx 32rpx 32rpx;
		margin: 0rpx 24rpx 24rpx 0rpx;
	}
	
	.commoDity_fd6_0_c2_c1_c0_c0 {
		font-size: 28rpx;
		font-weight: 500;
		color: rgba(0, 154, 255, 1);
		word-wrap: break-word;
	}
	
	.commoDity_fd6_0_c2_c1_c1 {
		border: 1px solid #BFBFBF;
		background: #FFFFFF;
		background-size: 100% !important;
		width: 144rpx;
		height: 64rpx;
		border-radius: 32rpx 32rpx 32rpx 32rpx;
		margin: 0rpx 24rpx 24rpx 0rpx;
	}
	
	.commoDity_fd6_0_c2_c1_c1_c0 {
		font-size: 28rpx;
		font-weight: 400;
		color: rgba(51, 51, 51, 1);
		word-wrap: break-word;
	}
	
	.commoDity_fd6_0_c3 {
		margin: 30rpx 32rpx 30rpx 32rpx;
	}
	
	.commoDity_fd6_0_c3_c0 {
		margin: 0rpx auto 0rpx 0rpx;
		font-size: 32rpx;
		font-weight: 500;
		color: rgba(51, 51, 51, 1);
		word-wrap: break-word;
	}
	
	::v-deep .commoDity_numberBoxInputfd6_0_c3_c1 {
		border: 1px solid #DCDCDC;
		background: #fff;
		background-size: 100% !important;
		width: 74rpx;
		height: 50rpx;
		text-align: center;
		color: #323232;
		font-size: 28rpx;
	}
	
	.commoDity_fd6_0_c3_c1_c0 {
		height: 50rpx;
		width: 52rpx;
		transform: translateY(5rpx);
	}
	
	.commoDity_fd6_0_c3_c1_c2 {
		height: 50rpx;
		width: 52rpx;
		transform: translateY(5rpx);
	}
	
	.commoDity_fd6_0_c4 {
		background: #3083FF;
		background-size: 100% !important;
		border-radius: 40rpx;
		font-size: 32rpx;
		color: #fff;
		width: 686rpx;
		height: 80rpx;
		line-height: 80rpx;
		font-weight: 500;
		margin: 0 32rpx 32rpx;
	}
	
	.commoDity_flex_6 {
		border-radius: 24rpx 24rpx 0rpx 0rpx;
		padding: 100rpx 0rpx 0rpx 0rpx;
	}
	
	
	
	
	
	
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: #fff;
		background-size: 100% auto !important;
	}

	.shoppingCart_flex_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.shoppingCart_fd0_0_c2_c0_1 {
		font-size: 32rpx;
		font-weight: 500;
		color: #3083FF;
	}

	.shoppingCart_fd0_0_c2_c0 {
		font-size: 32rpx;
		font-weight: 500;
		color: #2A2A2A;
	}

	.shoppingCart_fd0_0_c2 {
		padding: 0rpx 0rpx 0rpx 0rpx;
		width: 200rpx;
	}

	.shoppingCart_fd0_0_c1_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333333;
	}

	.shoppingCart_fd0_0_c0 {
		width: 200rpx;
	}

	.shoppingCart_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
		line-height: 88rpx;
	}
</style>